#include "src/parser/sql_parser.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* test_statements[] = {
    "DESCRIBE test_table;",
    "DESC test_table;", 
    "SHOW DATABASES;",
    "SHOW TABLES;",
    "SHOW COLUMNS FROM test_table;",
    "SHOW CREATE TABLE test_table;",
    "SHOW STATUS;",
    "USE test_database;",
    NULL
};

int main() {
    printf("=== SQL Parser Test for DESCRIBE Commands ===\n\n");
    
    for (int i = 0; test_statements[i] != NULL; i++) {
        printf("Testing: %s\n", test_statements[i]);
        
        parser_t* parser = parser_create(test_statements[i]);
        if (!parser) {
            printf("❌ Failed to create parser\n");
            continue;
        }
        
        statement_t* stmt = parser_parse_statement(parser);
        if (!stmt) {
            printf("❌ Failed to parse statement: %s\n", 
                   parser_get_error(parser) ? parser_get_error(parser) : "Unknown error");
        } else {
            printf("✅ Successfully parsed as: %s\n", stmt_type_to_string(stmt->type));
            
            // Print specific details based on statement type
            switch (stmt->type) {
                case STMT_DESCRIBE:
                    printf("   Table: %s\n", stmt->data.describe.table_name);
                    break;
                case STMT_USE:
                    printf("   Database: %s\n", stmt->data.use.database_name);
                    break;
                case STMT_SHOW_COLUMNS:
                case STMT_SHOW_CREATE_TABLE:
                    printf("   Table: %s\n", stmt->data.show.table_name);
                    break;
                case STMT_SHOW_TABLES:
                    if (stmt->data.show.database_name) {
                        printf("   Database: %s\n", stmt->data.show.database_name);
                    }
                    break;
                default:
                    break;
            }
            
            statement_destroy(stmt);
        }
        
        parser_destroy(parser);
        printf("\n");
    }
    
    printf("=== Parser Test Complete ===\n");
    return 0;
}